import plugin from '../../../lib/plugins/plugin.js'
import fs from 'fs'
import Yaml from '../model/Yaml.js'
import { segment } from "oicq";


let _path='./plugins/huasheng/resources/可莉语音/'
let path='./plugins/huasheng/config/只听我的_群号.yaml'

if (!fs.existsSync(path)) {fs.writeFileSync(path,'')}

export class ztwd extends plugin {
    constructor() {
        super({
            name: '判断该群是否<只听我的>',
            dsc: '',
            event: 'message.group',
            priority: -9999999999,
            rule: [
                {
                    reg: '^#*(只*听我的|听大家的?)$',
                    fnc: 'z',
                },
                {
                    reg: '',
                    fnc: 'ting',
                },
            ]
        })
   }
    async z(e) {
  if (!e.isMaster) 
  {return e.reply(segment.image(`${_path}99.jpg`))}
      let data=await Yaml.getread(path)
      if (!data) data= [];
      if (data.indexOf(e.group_id) == -1&&e.msg.includes('听我的')){
     await data.push(e.group_id)
     await e.reply(segment.image(`${_path}0.jpg`))
      }
      if (data.indexOf(e.group_id)!== -1&&e.msg.includes('听大家')){
     await data.splice(data.indexOf(e.group_id), 1)//位置索引，删除1个
     await e.reply(segment.image(`${_path}55.jpg`))
      }
      Yaml.getwrite(path,data)
}


async ting(e) {
   let group = await Yaml.getread(path)
   try {
        for (let qqq of group) {
          if(e.group_id == qqq &&!e.isMaster){
           return true
          }else{
          return false
          }
        }
      } catch (e) {
      return false
      }
      return false
}
}

